var app = getApp();
var that, categroyid;
Page({
  data: {
    navbar: ['兑换排行', '销量', '积分值', '筛选'],
    currentTab: 1,
    isChecked: 0,
    btn: false,
    list: true,
    screendownactive: true,
    block_img: true,
    mask: false,
    mask1:false,
    solt1: false,
    display_block: true,
    order_solt: false,
    changecolor: 0,
    ordersoltlist: ['综合排序', '新品优先'],
    shaixuan: false,
    shaixuanlist: ["不限", "10-2000", "2000-3000", "3000-4000", "4000-5000"],
    loadingHidden: false,
    navRightItems: [],
    desc: true
  },
  navbarTap: function (e) { //
    this.currentTab = e.currentTarget.dataset.idx
    this.data.mask = !this.data.mask
    this.data.mask1 = !this.data.mask1
    this.data.shaixuan = !this.data.shaixuan
    this.data.order_solt = !this.data.order_solt
    console.log(this.data.currentTab)
    this.setData({
      currentTab: this.currentTab,
      mask: this.data.mask,
      mask1: this.data.mask1,
      shaixuan: this.data.shaixuan,
      order_solt: this.data.order_solt,
      desc: !this.data.desc
    })
    if (e.currentTarget.dataset.idx == 1) {
      that = this
      wx.request({
        // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          parductSalesVolume: 1, 
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res, '销量')
          var list = res.data.list
          setTimeout(function () {
            that.setData({
              loadingHidden: true,
              navRightItems: list,
            })
          }, 500)
          that.setData({
            mask1: !that.data.mask1,
            order_solt: !that.data.order_solt,
          })
        }
      })
    }
  },
  list_check: function () {
    this.data.list = !this.data.list
    this.data.block_img = !this.data.block_img

    this.setData({
      list: this.data.list,
      // show: this.data.show,
      block_img: this.data.block_img,
    })
  },

  ordersolt: function (e) {//兑换排行
    that = this
    var changecolornew = e.currentTarget.dataset.idx
    console.log(changecolornew)
    this.setData({
      changecolor: changecolornew,
    })
    if (changecolornew == 1) {
      wx.request({
        //  url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          isNew: 1,
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res, '新品优先')
          var list = res.data.list
          console.log(list, "list1")
          setTimeout(function () {

            that.setData({
              loadingHidden: true,
              navRightItems: list,
            })


          }, 500)
          that.setData({
            mask1: !that.data.mask1,
            order_solt: !that.data.order_solt,
          })
        }
      })

    } else {
      wx.request({
        //  url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          isNew: 0,
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res, '综合优先')
          var list = res.data.list
          setTimeout(function () {
            that.setData({
              loadingHidden: true,
              navRightItems: list,

            })
          }, 500)
          that.setData({
            mask1: !that.data.mask1,
            order_solt: !that.data.order_solt,
          })
        }
      })
    }
  },

  descup() {//积分值 up down 
    wx.request({
      // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
      url: app.api.getshoplist(),
      method: 'POST',
      data: {
        page: 1,
        limit: 10,
        type: 2,
        parentId: JSON.parse(categroyid),
        parductIntegral: 1,
        companyId: app.globalData.shopData.companyId
      },
      success: function (res) {
        console.log(res, '积分')
        var list = res.data.list
        setTimeout(function () {
          that.setData({
            loadingHidden: true,
            navRightItems: list,
          })
        }, 500)
        that.setData({
          mask: !that.data.mask,
          order_solt: !that.data.order_solt,
        })
      }
    })
  },
  descdown() {
    wx.request({
      // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
      url: app.api.getshoplist(),
      method: 'POST',
      data: {
        page: 1,
        limit: 10,
        type: 2,
        parentId: JSON.parse(categroyid),
        parductIntegral: 0,
        companyId: app.globalData.shopData.companyId
      },
      success: function (res) {
        console.log(res, 'jifen')
        var list = res.data.list
        setTimeout(function () {
          that.setData({
            loadingHidden: true,
            navRightItems: list,
          })
        }, 500)
        that.setData({
          mask: !that.data.mask,
          order_solt: !that.data.order_solt,
        })
      }
    })
  },

  shaixuansolt: function (e) {
    that = this
    that.isChecked = e.currentTarget.dataset.idx
    console.log(e.currentTarget.dataset.idx)
    that.setData({
      isChecked: that.isChecked
    })
    if (e.currentTarget.dataset.idx == 1) {
      wx.request({
        // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          integralMin: 10,
          integralMax: 1000,
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res.data.list, 'jifen')
          var list = res.data.list
          setTimeout(function () {
            that.setData({
              loadingHidden: true,
              navRightItems: list,
            })
          }, 500)
          that.setData({
            mask: !that.data.mask,
            shaixuan: !that.data.shaixuan,
          })
        }
      })
    } else if (e.currentTarget.dataset.idx == 2) {
      wx.request({
        // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          integralMin: 2000,
          integralMax: 3000,
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res, 'jifen')
          var list = res.data.list
          setTimeout(function () {
            that.setData({
              loadingHidden: true,
              navRightItems: list,
            })
          }, 500)
          that.setData({
            mask: !that.data.mask,
            shaixuan: !that.data.shaixuan,
          })
        }
      })
    } else if (e.currentTarget.dataset.idx == 3) {
      wx.request({
        // url: 'http://172.188.88.232:8080/hyParductManage/getPageList',
        url: app.api.getshoplist(),
        method: 'POST',
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          integralMin: 3000,
          integralMax: 4000,
          companyId: app.globalData.shopData.companyId
        },
        success: function (res) {
          console.log(res, 'jifen')
          var list = res.data.list
          setTimeout(function () {
            that.setData({
              loadingHidden: true,
              navRightItems: list,
            })
          }, 500)
          that.setData({
            mask: !that.data.mask,
            shaixuan: !that.data.shaixuan,
          })
        }
      })
    } else {
      app.getData({
        url: app.api.getshoplist(),
        method: "POST",
        data: {
          page: 1,
          limit: 10,
          type: 2,
          parentId: JSON.parse(categroyid),
          companyId: app.globalData.shopData.companyId
        },
        ok: function (res) {
          if (res.statusCode == 200 && res.errMsg == 'request:ok') {

              var list = res.data.list
              setTimeout(function () {
                if (res.data.code == 1) {
                  that.setData({
                    loadingHidden: true,
                    navRightItems: list,
                  })
                } else {
                  wx.showToast({
                    title: res.data.message,
                  })
                }
              }, 500)
            } else {
              wx.showToast({
                title: res.data.message,
              })
            } that.setData({
              mask: !that.data.mask,
              shaixuan: !this.data.shaixuan,
            })
          }
        

      })

    }
  },
  onLoad: function (options) {//获取url携带id值
    that = this
    // that.descup()
    categroyid = options.id
    //console.log(categroyid)
    // 列表接口
    app.getData({
      url: app.api.getshoplist(),
      method: "POST",
      data: {
        page: 1,
        limit: 10,
        type: 2,
        parentId: JSON.parse(categroyid),
        companyId: app.globalData.shopData.companyId
      },
      ok: function (res) {
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
            var list = res.data.list
            setTimeout(function () {
              if (res.data.code == 1) {
                that.setData({
                  loadingHidden: true,
                  navRightItems: list,
                })
              } else {
                wx.showToast({
                  title: res.data.message,
                })
              }
            }, 500)
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
    })


  },

})

